<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>制定安全库存配置单</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../../css/public.css" media="all">
	</head>

	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">
				<!--搜索开始-->
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="" id="searchFrm">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">产品名称</label>
									<div class="layui-input-inline">
										<input type="text" name="productName" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">查询时间</label>
									<div class="layui-input-inline">
										<input type="text" id="registerTime" name="registerTime" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
									<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label
										 class="layui-icon layui-icon-refresh"></label>重置</a>
								</div>
							</div>
						</form>
					</div>
				</fieldset>
				<!--搜索结束-->

				<table id="ProductFile" lay-filter="test"></table>

				<!--修改的弹出层-->
				<div class="layui-row" id="update" style="display:none;">
					<div class="layui-col-md10" align="center">
						<form class="layui-form layui-from-pane" style="margin-top: 20px;" id="accountFomat">
							<div class="layui-form-item"><label class="layui-form-label">产品编号:</label>
								<div class="layui-input-block"><input type="text" name="productId" id="productId" autocomplete="off"
									 placeholder="请输入产品编号" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item"><label class="layui-form-label">产品名称:</label>
								<div class="layui-input-block"><input type="text" name="productName" id="productName" autocomplete="off"
									 placeholder="请输入产品名称" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width: 105px;">库存报警下限数:</label>
								<div class="layui-input-inline"><input type="text" name="minAmount" id="minAmount" autocomplete="off"
									 placeholder="请输入库存报警下限数" class="layui-input">
								</div>
								<label class="layui-form-label" style="width: 105px;">库存报警上限数:</label>
								<div class="layui-input-inline"><input type="text" name="maxAmount" id="maxAmount" autocomplete="off"
									 placeholder="请输入库存报警上限数" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">登记人:</label>
								<div class="layui-input-inline"><input type="text" name="register" id="register" autocomplete="off" placeholder="请输入登记人"
									 class="layui-input">
								</div>
								<label class="layui-form-label">登记时间</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input" id="registerTime" name="registerTime" placeholder="yyyy-MM-dd">
								</div>
								<label class="layui-form-label" style="margin-top: 20px;">设计人:</label>
								<div class="layui-input-inline" style="margin-top: 20px;"><input type="text" name="Designer" id="Designer"
									 autocomplete="off" placeholder="请输入设计人" class="layui-input">
								</div>
							</div>
							<table id="RepertoryCell" lay-filter="test"></table>
							<table border="1px" bordercolor="#E6E6E6" width="800px" height="60px" style="margin-bottom: 20px; margin-left: 30px;">
								<tr align="center" bgcolor="#F2F2F2">
									<td>序号</td>
									<td>库房名称</td>
									<td>储存地址编号</td>
									<td>储存地址名称</td>
									<td>存储单元简称</td>
									<td>最大存储量</td>
									<td>存储单位</td>
								</tr>
								<tr align="center">
									<td id="pid"></td>
									<td id="storeName" contentEditable="true"></td>
									<td id="Kind"></td>
									<td id="type"></td>
									<td id="storageUnitShorted" contentEditable="true"></td>
									<td id="maxCapacityAmount" contentEditable="true"></td>
									<td id="amountUnit" contentEditable="true"></td>
								</tr>
							</table>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">配置要求</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入内容" class="layui-textarea" id="config" name="config"></textarea>
								</div>
							</div>
							<!--隐藏的用户id-->
							<input type="text" name="accountId" id="accountId" hidden>
							<div class="layui-form-item" style="margin-top:40px">
								<div class="layui-input-block">
									<input class="layui-btn" type="button" lay-submit="*" lay-filter="dataForm" value="提交">
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/common.js" charset="utf-8"></script>
		<script src="../../../lib/common/selectLayer.js" charset="utf-8"></script>
		<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['table', 'jquery', 'form', 'laydate'], function() {
				var table = layui.table,
					layer = layui.layer,
					form = layui.form,
					$ = layui.jquery,
					laydate = layui.laydate;

				var pid;
				var kind;
				var type;
				var productName;
				var registerTime;

				var mainIndex;

				laydate.render({
					elem: '#registerTime'
				});

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					console.log(obj.data)
					if (obj.event === 'edit') {
						$("#productId").val(data.productId);
						$("#pid").html(data.id);
						pid = data.id;
						$("#Kind").html(data.firstKindId + "-" + data.secondKindId + "-" + data.thirdKindId);
						kind = data.firstKindId + "-" + data.secondKindId + "-" + data.thirdKindId;
						$("#type").html(data.firstKindName + "-" + data.secondKindName + "-" + data.thirdKindName);
						type = data.firstKindName + "-" + data.secondKindName + "-" + data.thirdKindName;
						$("#productName").val(data.productName);
						productName = data.productName;
						$("#Designer").val(data.register)
						$("#registerTime").val(data.registerTime);
						registerTime = data.registerTime;
						mainIndex = layer.open({
							type: 1,
							title: '安全库存配置设计单',
							area: ['860px', '650px'],
							content: $("#update"),
							success: function(layero, index) {
								// 重新渲染弹层中的下拉选择框select
								form.render();
							}
						});
					}
				});

				//第一个实例
				var tableIns = table.render({
					elem: '#ProductFile',
					url: api7 + 'ProductFile/productFileList' //数据接口
						,
					page: true //开启分页
						,
					cols: [
						[ //表头
							{
								field: 'productId',
								title: '产品编号',
								sort: true,
								fixed: 'left'
							}, {
								field: 'productName',
								title: '产品名称'
							}, {
								field: 'type',
								title: '用途类型',
								templet: '#forType'
							}, {
								field: 'productClass',
								title: '档次级别',
								templet: '#forProductClass'
							}, {
								field: 'firstKindName',
								title: '一级分类'
							}, {
								field: 'secondKindName',
								title: '二级分类'
							}, {
								field: 'thirdKindName',
								title: '三级分类'
							}, {
								field: 'id',
								title: '制定',
								templet: '#formulate'
							}
						]
					]
				});

				form.on('submit(dataForm)', function(data) {
					if (data.field.minAmount >= data.field.maxAmount) {
						layer.msg("库存报警下限数不能等于大于库存报警上限");
						return false;
					}else if(data.field.minAmount==""|| data.field.maxAmount==""||data.field.register==""||data.field.registerTime==""||$("#storeName").text()==""||$("#storageUnitShorted").text()==""||$("#maxCapacityAmount").text()==""||$("#amountUnit").text()==""){
						layer.msg("各项数据均不能为空");
						return false;
					} else {
						//生成配置单编号
						var designId = '401';
						var serialNumber = Math.floor(Math.random() * 9000 + 999);
						designId += serialNumber

						$.ajax({
							url: api7 + "RepertoryCell/makeconfig",
							method: "post",
							data: {
								productName: productName,
								id: pid,
								firstKindId: kind,
								firstKindName: type,
								productId: data.field.productId,
								minAmount: data.field.minAmount,
								maxAmount: data.field.maxAmount,
								storeId: designId,
								register: data.field.register,
								registerTime: data.field.registerTime,
								storeName: $("#storeName").text(),
								storageUnitShorted: $("#storageUnitShorted").text(),
								maxCapacityAmount: $("#maxCapacityAmount").text(),
								amountUnit: $("#amountUnit").text(),
								config: data.field.config
							},
							success: function(res) {
								if (res.code == 200) {
									layer.msg(res.msg);
									tableIns.reload();
								}
								layer.close(mainIndex);
							}
						})
					}
				})

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var params = $("#searchFrm").serialize();
					//执行搜索重载
					table.reload('ProductFile', {
						page: {
							curr: 1
						},
						url: api7 + 'ProductFile/productFileList?' + params
					});
					return false;
				});

			});
		</script>
		<script type="text/html" id="forType">
			{{# if(d.type=='Y001-1'){d.type='商品'}}
				{{d.type}}
			{{# }else{d.type='物料'}}
				{{d.type}}
			{{# }}}
		</script>
		<script type="text/html" id="forProductClass">
			{{# if(d.productClass=='D001-1'){d.productClass='高档'}}
				{{d.productClass}}
			{{# }else if(d.productClass=='D001-2'){d.productClass='中档'}}
				{{d.productClass}}
			{{# }else{d.productClass='抵挡'}}
				{{d.productClass}}
			{{# }}}
		</script>
		<script type="text/html" id="formulate">
			<button class="layui-btn layui-btn-xs" lay-event="edit">制定</button>
		</script>
	</body>

</html>
